package com.beordie.utils;

import java.util.List;

/**
 * @Classname PageUtils
 * @Description TODO
 * @Date 2021/6/9 14:12
 * @Created 30500
 */
public class PageUtils {
    // 页码值
    private Integer pageIndex;
    // 页码容量
    private Integer pageSize = 8;
    // 查询结果集
    private List dataList;
    // 结果总条数
    private Integer total = 0;
    // 总页数
    private Integer totalPages = 1;

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        // 页码不能小于1, 也不能大于最大页数
        if (pageIndex < 1) {
            pageIndex = 1;
        }
        this.pageIndex = pageIndex;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public List getDataList() {
        return dataList;
    }

    public void setDataList(List dataList) {
        this.dataList = dataList;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
        setTotalPages();
    }

    public Integer getTotalPages() {
        return this.totalPages;
    }

    public void setTotalPages() {
        this.totalPages = this.total % this.pageSize > 0 ? this.total / this.pageSize + 1: this.total / this.pageSize;
    }
}
